import request from '@/utils/request'

// 查询考勤信息列表
export function listSignRecord(query) {
  return request({
    url: '/attendanceManagement/signRecord/list',
    method: 'get',
    params: query
  })
}

// 【教师】查询考勤信息列表
export function listSignRecordForTeacher(query) {
  return request({
    url: '/attendanceManagement/signRecord/teacher/list',
    method: 'get',
    params: query
  })
}

// 【教师】统计学生考勤信息
export function analysisSignRecordForTeacher(query) {
  return request({
    url: '/attendanceManagement/signRecord/teacher/analysis',
    method: 'get',
    params: query
  })
}

// 考勤详情
export function listSignRecordForDetail(query) {
  return request({
    url: '/attendanceManagement/signRecord/teacher/signDetail',
    method: 'get',
    params: query
  })
}

/**
 * 根据 courseId 获取考勤记录 ID
 * @param {number} courseId - 课程 ID
 * @returns {Promise} - 返回一个 Promise 对象，包含请求结果
 */
export function getCourseRecordIdByCourseId(courseId) {
  return request({
    url: '/attendanceManagement/signRecord/teacher/getCourseRecordId',
    method: 'get',
    params: {
      courseId
    }
  });
}

/**
 * 获取二维码链接
 * @returns {Promise} - 返回一个 Promise 对象，包含请求结果
 */
export function getCodeLink() {
  return request({
    url: '/attendanceManagement/signRecord/teacher/getCodeLink',
    method: 'get'
  });
}

/**
 * 根据 courseId 获取考勤类型
 * @param {number} courseId - 课程 ID
 * @returns {Promise} - 返回一个 Promise 对象，包含请求结果
 */
export function getAttendanceTypeByCourseId(courseId) {
  return request({
    url: '/attendanceManagement/signRecord/teacher/getAttendanceType',
    method: 'get',
    params: {
      courseId
    }
  });
}

// 【教师】查询考勤信息详细
export function getSignRecord(userId, courseRecordId) {
  return request({
    url: '/attendanceManagement/signRecord',
    method: 'get',
    params: {
      userId,
      courseRecordId
    }
  })
}

// 新增考勤信息
export function addSignRecord(data) {
  return request({
    url: '/attendanceManagement/signRecord',
    method: 'post',
    data: data
  })
}

// 修改考勤信息
export function updateSignRecord(data) {
  return request({
    url: '/attendanceManagement/signRecord',
    method: 'put',
    data: data
  })
}

// 删除考勤信息
export function delSignRecord(courseRecordId) {
  return request({
    url: '/attendanceManagement/signRecord/' + courseRecordId,
    method: 'delete'
  })
}
